<?php
//命名空间声明
namespace Admin\Controller;
//引入父类控制器
use Think\Controller;
//声明类并且继承父类
class PublicController extends Controller{

	//登录页面展示
	public function login(){
		//展示模版
		$this -> display();
	}
	public function captcha(){
		$cfg=array(
			'fontSize'=>12,
			'useCurve'=>false,
			'useNoise'=>false,
			'length'=>4,
			'imageW'=>80,
			'imageH'=>40,
			'fontttf'=>'4.ttf'
		);
		$verify=new \Think\Verify($cfg);
		$verify->entry();

	}
	public function checkLogin(){
		$post=I('post.');
		$verify=new \Think\Verify();
		$result=$verify->check($post['captcha']);
		if($result){
			$model=M('User');
			unset($post['captcha']);
			$data=$model->where($post)->find();
			if($data){
				session('id',$data['id']);
				session('username',$data['username']);
				session('role_id',$data['role_id']);
				$this->success('登录成功!',U('Index/index'),3);
			}else{
				$this->error('用户名或密码错误');
			}
		}else{
			$this->error('您输入的验证码错误');
		}
	}
	public function logout(){
		session(null);
		$this->success('退出成功',U('login'),1);
	}
}